package com.rt.cms.service.impl;

import com.rt.cms.common.base.Page;
import com.rt.cms.common.base.PageResultSet;
import com.rt.cms.dao.TbApprovalRecordMapper;
import com.rt.cms.data.entity.TbApprovalRecord;
import com.rt.cms.service.ApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 日志服务
 * Created by lgx on 2018/05/24.
 */
@Service
public class ApprovalServiceImpl implements ApprovalService {

    @Autowired
    TbApprovalRecordMapper approvalRecordMapper;

    @Override
    public List<TbApprovalRecord> queryApprovalRecordByUsrId(int comInfoId) {
        return approvalRecordMapper.queryApprovalRecordByUsrId(comInfoId);
    }

    @Override
    public List<TbApprovalRecord> queryDormanyRecordByUsrId(int comInfoId) {
        return approvalRecordMapper.queryDormanyRecordByUsrId(comInfoId);
    }

    @Override
    public List<TbApprovalRecord> queryWaitDormanyRecordByUsrId(int comInfoId) {
        return approvalRecordMapper.queryWaitDormanyRecordByUsrId(comInfoId);
    }

    public PageResultSet<TbApprovalRecord> queryHistoryRecord(Integer id, Page page) {

        Long count = approvalRecordMapper.selectCount(id);
        List<TbApprovalRecord> dtoList = new ArrayList<>();
        approvalRecordMapper.selectByParam(id,page.getOffset(),page.getLimit()).forEach(approvalRecord -> {
            dtoList.add(approvalRecord);
        });
        PageResultSet<TbApprovalRecord> resultSet = new PageResultSet<>();
        resultSet.setRows(dtoList);
        resultSet.setTotal(count);

        return resultSet;
    }

    public PageResultSet<TbApprovalRecord> queryDormanyRecord(Integer id, Page page) {

        Long count = approvalRecordMapper.selectDormanyCount(id);
        List<TbApprovalRecord> dtoList = new ArrayList<>();
        approvalRecordMapper.selectDormanyByParam(id,page.getOffset(),page.getLimit()).forEach(approvalRecord -> {
            dtoList.add(approvalRecord);
        });
        PageResultSet<TbApprovalRecord> resultSet = new PageResultSet<>();
        resultSet.setRows(dtoList);
        resultSet.setTotal(count);

        return resultSet;
    }
}
